package cn.zongjie.day07;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.Comparator;
import java.util.TreeSet;

public class Test01 {
    public static void main(String[] args) {
        DateTimeFormatter dtf = DateTimeFormatter.ofPattern("y/MM/dd");
        TreeSet<Student> list = new TreeSet<>(new Comparator<Student>() {
            @Override
            public int compare(Student o1, Student o2) {
                LocalDate p1 = LocalDate.parse(o1.getBirthday(), dtf);
                LocalDate p2 = LocalDate.parse(o2.getBirthday(), dtf);
                if (p1.isBefore(p2)) {
                    return 1;
                } else if (p1.isAfter(p2)) {
                    return -1;
                } else {
                    return o2.getCode() - o1.getCode();
                }
            }
        });

        list.add(new Student("岳亚东", 33, "1992/12/16"));
        list.add(new Student("金小强", 39, "1992/02/16"));
        list.add(new Student("王庭伟", 45, "1992/12/16"));
        list.add(new Student("邓威", 46, "1992/03/16"));
        list.add(new Student("马樱文", 58, "1992/12/16"));
        list.add(new Student("孙鹏生", 4, "1995/10/10"));
        list.add(new Student("关锐", 5, "1991/01/10"));
        list.add(new Student("李海波", 20, "1997/09/10"));
        list.add(new Student("王泽琪", 42, "1992/02/16"));

        System.out.println(list);
    }
}
